package com.ugood.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: list获取对应的条数
 * @Author: org
 * @CreateDate: 2018/7/5 10:56
 */
public class ListSortPageUtil {

    /**
     * 获取list指定下标 分页
      * @param datas
     * @param pageIndex
     * @param pageSize
     * @param <T>
     * @return
     */
    public static <T> List<T> pageBean(List<T> datas, int pageIndex, int pageSize){
        List<T> result = new ArrayList<T>();
        int pageIndexStart = (pageIndex-1)*pageSize;//获取list起始index
        int pageIndexEnd = pageIndex*pageSize-1;//获取list结束index
        if(datas.size()-1 <= pageIndexEnd){
            pageIndexEnd = datas.size()-1;
        }

        for(int i=pageIndexStart;i<=pageIndexEnd;i++){
            result.add(datas.get(i));
        }
        return result;
    }
}
